package com.example.kliven.because.imagecache;import android.graphics.Bitmap;import android.util.LruCache;import com.android.volley.toolbox.ImageLoader;/** * Created by Kliven on 16/1/18. */public class MemoryCache implements ImageLoader.ImageCache {    private LruCache<String, Bitmap> cache;    public MemoryCache(){        long maxMemory = Runtime.getRuntime().maxMemory(); // 获取系统最大内存;        int cacheSize = (int) (maxMemory / 4); // 图片最大大小;        cache = new LruCache<String, Bitmap>(cacheSize){            @Override            protected int sizeOf(String key, Bitmap value) {// 重新计算图片大小                return value.getRowBytes() * value.getHeight() / 1024;            }        };    }    @Override    public Bitmap getBitmap(String url) {        return cache.get(url);    }    @Override    public void putBitmap(String url, Bitmap bitmap) {        cache.put(url,bitmap);    }}